<template>
  <div class="change-class body-bg">
    <div v-if="!initLoading">
      <ul class="change-content" v-if="list.length">
        <li class="change-items" v-for="(item,index) in list" :key="index">
          <div class="middle border-bottom">报名时间：{{item.dateTime}} <van-tag plain round color="#00B8EE">已报名</van-tag></div>
          <div class="top border-bottom">
            <img class="head-img" :src="item.headImg" alt="头像">
            <div class="class-infor">
              <p class="class-name overflow-tow">{{item.title}}</p>
              <p class="text">活动时间：{{item.startTime}}-{{item.endTime}}</p>
              <p class="text">活动地点：{{item.address}}</p>
            </div>
          </div>
          <div class="bottom">
            <van-button color="#00B8EE" size="small" @click="cancelSign">取消报名</van-button>
          </div>
        </li>
        <li v-if="isReachBottom" class="pull-loading"><van-loading type="spinner" size="20px" color="#1989fa" /></li>
        <li v-if="isBottom" class="bottom-line">-- 亲，已经到最后了--</li>
      </ul>
      <div v-else class="empty">
        <img src="/static/images/empty-icon.png" alt="空">
        <p class="empty-tips">暂时还没有可补课级哦</p>
      </div>
    </div>
    <div v-else class="init-loading"><van-loading type="spinner" color="#1989fa" /></div>
  </div>
</template>

<script>
import store from '../../store/globalStore'
export default {
  data() {
    return {
      initLoading: true, // 初始加载
      isBottom: false, // 是否加载完全部数据
      isReachBottom: false, // 是否显示加载状态
      list: [
        {state:"1", title: "文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案文案", headImg: 'https://img.yzcdn.cn/vant/cat.jpeg', dateTime: "2019-11-07 12:20:31", startTime:'2019-12-12', endTime:'2019-12-12', address:"知春路校区"},
        {state:"2", title: "文案文案文案文案文案文案文案文案文", headImg: 'https://img.yzcdn.cn/vant/cat.jpeg', dateTime: "2019-11-07 12:20:31", startTime:'2019-12-12', endTime:'2019-12-12', address:"知春路校区"},
        {state:"2", title: "文案文案文案文案文案文案文案文案文", headImg: 'https://img.yzcdn.cn/vant/cat.jpeg', dateTime: "2019-11-07 12:20:31", startTime:'2019-12-12', endTime:'2019-12-12', address:"知春路校区"},
        {state:"2", title: "文案文案文案文案文案文案文案文案文", headImg: 'https://img.yzcdn.cn/vant/cat.jpeg', dateTime: "2019-11-07 12:20:31", startTime:'2019-12-12', endTime:'2019-12-12', address:"知春路校区"},
        {state:"2", title: "文案文案文案文案文案文案文案文案文", headImg: 'https://img.yzcdn.cn/vant/cat.jpeg', dateTime: "2019-11-07 12:20:31", startTime:'2019-12-12', endTime:'2019-12-12', address:"知春路校区"},
      ]
    }
  },
  onShow() {
    this.getShiftWorkList();
  },
  methods: {
    // 获取列表
    getShiftWorkList() {
      this.$fetch.shiftWork()
      .then(res=>{
        this.initLoading = false;
      }).catch(err=>{
        this.initLoading = false;
      })
    },
    // 取消报名
    cancelSign() {
      
    }
  },
  // 下拉刷新
  onPullDownRefresh: function() {
    console.log("下拉刷新");
    wx.showNavigationBarLoading() //在标题栏中显示加载
    //模拟加载
    setTimeout(function(){
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    },1500);
  },
  // 上拉加载
  onReachBottom () {
    let that = this;
    that.isReachBottom = true;
    wx.showNavigationBarLoading() //在标题栏中显示加载
    if(that.list.length<10){
      setTimeout(function(){
        that.isReachBottom = false;
        wx.hideNavigationBarLoading() //完成停止加载
        //模拟加载
        that.list = [...that.list,...that.list]
      },1500);
    } else {
      that.isReachBottom = false;
      that.isBottom = true;
      wx.hideNavigationBarLoading() //完成停止加载
    }
  },
}
</script>

<style lang="less" scope>
.change-class{
  width: 100%;
  min-height: 100vh;
  border-top: 0.5px solid #dcdcdc;
  .change-content{
    width: 100%;
    .change-items{
      width: 100%;
      background: #fff;
      position: relative;
      overflow: hidden;
      margin-bottom: 10px;
      &:last-child{
        border-bottom: 0;
      }
      .top{
        width: 100%;
        padding: 12px 15px;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .middle{
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 15px 15px;
        box-sizing: border-box;
        font-size: 12px;
        color: #8D8D8D;
      }
      .bottom{
        width: 100%;
        padding: 8px 15px;
        box-sizing: border-box;
        display: flex;
        flex-direction: row-reverse;
        .bottom-btn{
          width: 84px;
          text-align: center;
          padding: 8px 0;
          border: 0.5px solid rgba(0,184,238,1);
          border-radius:  14px;
          font-size: 14px;
          color: #00B8EE;
          background: #fff;
          margin-right: 15px;
          &.sureRecive{
            border: 0.5px solid rgba(194,194,194,1);
            color: #C2C2C2;
          }
        }
      }
      .head-img{
        min-width: 80px;
        width: 80px;
        height: 80px;
        display: block;
      }
      .zhuanban-state{
        width: 50px;
        height: 16px;
        display: flex;
        align-items: center;
        text-indent: 6px;
        font-size: 10px;
        color: #fff;
        position: absolute;
        top: 0;
        left: 0;
        overflow: hidden;
        &::after{
          content: "";
          width: 20px;
          height: 20px;
          background: #fff;
          position: absolute;
          top: 5px;
          right: -10px;
          transform: rotate(45deg);
        }
      }
      .class-infor{
        height: 80px;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin-left: 20px;
        .class-name{
          width: 100%;
          font-size: 14px;
          color: #333;
        }
        .class-top{
          display: flex;
          width: 100%;
          font-size: 14px;
          font-weight: bold;
        }
        .text{
          font-size: 12px;
          color: #888;
        }
        .change-btn{
          display: flex;
          justify-content: center;
          align-items: center;
          min-width: 54px;
          height: 20px;
          text-align: center;
          font-size: 14px;
          color: #fff;
          margin-left: 12px;
          background: #00B7EE;
          border-radius: 10px;
        }
      }
    }
  }
}
</style>
